﻿<cfscript>
/** 
* Senate Frameworks graduateProgressProperty
* 
* @hint "The Term Credit progress property object handler." 
*/ 

component 
	displayname="public.service.handler.graduateProgressProperty" 
	output=false 
	accessors=true 
	{
		
	/* PROPERTIES */

	/**
	* @hint "初始化对象"
	*/
	public public.service.handler.graduateProgressProperty function init() output=false {
		this.hashMap = structNew();
		return this;
	}
	
	/**
	* @hint "必修课学分"
	* 
	* @creditList "学分列表"
	*/
	public string function parseCreditRequired( required string creditList) output=false {
		
		for (var i=1; i lte listLen(arguments.creditList); i++) {
			setCreditRequiredByTerm(i, listGetAt(arguments.creditList, i));
		}
		
	}

	/**
	* @hint "总学分"
	* 
	* @creditList "学分列表"
	*/
	public string function parseCredit( required string creditList) output=false {
		
		for (var i=1; i lte listLen(arguments.creditList); i++) {
			setCreditByTerm(i, listGetAt(arguments.creditList, i));
		}
		
	}
	
	/**
	* @hint "学期必修课学分进度"
	* 
	* @SchoolingLength "学制"
	*/
	public string function getCreditRequired( required numeric SchoolingLength ) output=false {
		
		var creditList = "";
		
		for (var i=1; i lte 2*arguments.SchoolingLength; i++) {
			creditList = listAppend(creditList, getCreditRequiredByTerm(i));
		}
		
		return creditList;
	}

	/**
	* @hint "学期学分进度"
	* 
	* @SchoolingLength "学制"
	*/
	public string function getCredit( required numeric SchoolingLength ) output=false {

		var creditList = "";
		
		for (var i=1; i lte 2*arguments.SchoolingLength; i++) {
			creditList = listAppend(creditList, getCreditByTerm(i));
		}
		
		return creditList;
	
	}
	
	/**
	* @hint "设置学期必修课学分"
	* 
	* @Term "学期序号"
	* @Credit "学分"
	*/
	public void function setCreditRequiredByTerm( required string Term, required numeric Credit) output=false {
		structInsert(this.hashMap, "R"&numberFormat(arguments.Term, '0_'), arguments.Credit, true);
	}
	
	/**
	* @hint "设置学期总学分"
	* 
	* @Term "学期序号"
	* @Credit "学分"
	*/
	public void function setCreditByTerm( required string Term, required numeric Credit) output=false {
		structInsert(this.hashMap, "A"&numberFormat(arguments.Term, '0_'), arguments.Credit, true);
	}
	
	/**
	* @hint "读取学期必修课学分"
	* 
	* @Term "学期序号"
	*/
	public numeric function getCreditRequiredByTerm( required string Term ) output=false {
		
		if (structKeyExists(this.hashMap, "R"&numberFormat(arguments.Term, '0_'))) {
			return this.hashMap["R"&numberFormat(arguments.Term, '0_')];
		}
		return 0;
	}

	/**
	* @hint "读取学期总学分"
	* 
	* @Term "学期序号"
	*/
	public numeric function getCreditByTerm( required string Term ) output=false {
		
		if (structKeyExists(this.hashMap, "A"&numberFormat(arguments.Term, '0_'))) {
			return this.hashMap["A"&numberFormat(arguments.Term, '0_')];
		}
		return 0;
	}

}

</cfscript>